package com.overlord.im.connector.message.resolver;

import com.alibaba.fastjson.JSON;
import com.overlord.im.commons.constant.MsgType;
import com.overlord.im.commons.message.OverlordImMessage;
import com.overlord.im.connector.message.service.SendMessageService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName SimpleMessageResolver
 * @Author wuwei
 * @Description NONE
 * @Date 2020/6/2 14:01
 **/
@Slf4j
public class SimpleMessageResolver implements Resolver {

    private SendMessageService sendMessageService;

    public SimpleMessageResolver(SendMessageService sendMessageService) {
        this.sendMessageService = sendMessageService;
    }

    @Override
    public boolean support(OverlordImMessage message) {
        return message.getMsgType() == MsgType.CHAT || message.getMsgType() == MsgType.GROUP_CHAT;
    }

    @Override
    public void resolve(OverlordImMessage message, ChannelHandlerContext ctx) {
        log.debug("SimpleMessageResolver接收到消息:{}", JSON.toJSONString(message));
        sendMessageService.send(message, ctx);
    }
}
